// miniprogram/pages/me/me.js
var that
var app = getApp();
const db = wx.cloud.database();
const _ = db.command;
Page({
    //收藏和喜欢
       /**
   * 页面的初始数据
   */
  data: {
    follow:0,
    fans:0,
    collect:0,
    topics:{},
   },
     /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    that = this
    wx.cloud.init({
      env: 'test-5gwxfg0see31cde1',
    })

    //获取关注数量
    db.collection('follow')
    .count({
      success:function(res){
        that.data.follow = res.total
        that.setData({
          follow: that.data.follow
        })
      }
    })
  
     //获取粉丝数量
     db.collection('fans').doc(app.globalData.openid)
     .field({
       fans : true
     })
     .get({
        success:function(res){
          console.log("粉丝量")
          console.log(res.data.fans)
          that.data.fans = res.data.fans
          that.setData({
            fans : that.data.fans
          })
        }
     })
     //获赞和收藏
     db.collection('topic')
     .where({
       _openid : app.globalData.openid
     })
     .field({
        isLike:true,
        collect:true
     })
     .get({
       success:function(res){
           console.log(res.data)
           var s1 =0;
           for(var i=0;i<res.data.length;i++){
             console.log(res.data[i].isLike)
             console.log(res.data[i].collect)
             s1 = s1 + res.data[i].isLike + res.data[i].collect;
           }
           that.data.collect = s1 
           that.setData({
             collect : that.data.collect
           })
       }
     })
 
  },
  /**
   * 收藏列表
   */
  onCollectClick:function(event){
    wx.navigateTo({
      url: '../userDetail/userDetail?flat='+ 1,
    })
  },
  /**
   * 点赞列表
   */
  onLikeClick:function(event){
    wx.navigateTo({
      url:'../userDetail/userDetail?flat='+ 2,
    })
  },
   /**
   * 关注列表
   */
  onFollowClick:function(event){
    wx.navigateTo({
      url:'../userDetail/userDetail?flat='+ 4,
    })
  },
   /**
   * 历史列表
   */
  onHistoryClick:function(event){
    wx.navigateTo({
      url:'../userDetail/userDetail?flat='+ 3,
    })
  },

  /**
   * 提交意见
   */
  onAdviceClick:function(event){
    wx.navigateTo({
      url: '../advance/advance',
    })
  },
  /** 
  咨询师申请
  */
 onApplyClick:function(){
    wx.navigateTo({
      url: '../apply/apply',
    })
 },
   /** 用户点击右上角分享
   */
  onShareAppMessage: function(event) {
    console.log(event);
  },
})